﻿<%@ Page Language="C#" MasterPageFile="~/Safty/MasterPage.master" AutoEventWireup="true" CodeFile="UserList.aspx.cs" Inherits="Safty_UserList" Title="无标题页" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<ext:TokenScript ID="TokenScript1" runat="server">
        <script type="text/javascript">
            var applyFilter = function () {
                #{Store1}.filterBy(getRecordFilter());
            }
            
            var clearFilter = function () {
                #{CompanyFilter}.reset();
                #{uidFilter}.reset();
                #{deptFilter}.reset();                 
                
                #{Store1}.clearFilter();
            }

            var filterString = function (value, dataIndex, record) {
                var val = record.get(dataIndex);
                if (typeof val != "string") {
                    return value.length == 0;
                }
                return val.toLowerCase().indexOf(value.toLowerCase()) > -1;
            }

            var filterDate = function (value, dataIndex, record) {
                var val = record.get(dataIndex).clearTime(true).getTime();

                if (!Ext.isEmpty(value, false) && val != value.clearTime(true).getTime()) {
                    return false;
                }
                return true;
            }

            var filterNumber = function (value, dataIndex, record) {
                var val = record.get(dataIndex);			    

                if (!Ext.isEmpty(value, false) && val != value) {
                    return false;
                }
                return true;
            }

            var getRecordFilter = function () {
                var f = [];

                f.push({
                    filter: function(record) {                         
                        return filterNumber(#{uidFilter}.getValue(), 'uID', record);
                    }
                });
                f.push({
                    filter: function(record) {                         
                        return filterString(#{deptFilter}.getValue(), 'DeptName', record);
                    }
                });
                f.push({
                    filter: function(record) {                         
                        return filterString(#{CompanyFilter}.getValue(), 'username', record);
                    }
                }); 

                var len = f.length;
                return function(record) {
                    for (var i = 0; i < len; i++) {
                        if (!f[i].filter(record)) {
                            return false;
                        }
                    }
                    return true;
                };
            }  
        </script>
    </ext:TokenScript>
                         <asp:SqlDataSource ID="SqlDataSource3"
                            ConnectionString="<%$ ConnectionStrings:CXDB %>" 
                             SelectCommand="Select username from cx_userbase"
                             runat="server"></asp:SqlDataSource>
                               <ext:Store ID="usernameStore" DataSourceID="SqlDataSource3" runat="server">
                                    <Reader>
                                        <ext:JsonReader ReaderID="username">
                                            <Fields>
                                                <ext:RecordField Name="username" />
                                            </Fields>
                                        </ext:JsonReader>
                                    </Reader>
                                </ext:Store>
                                <asp:SqlDataSource ID="SqlDataSource4"
                            ConnectionString="<%$ ConnectionStrings:CXDB %>" 
                             SelectCommand="Select DeptName from cx_sys_dept"
                             runat="server"></asp:SqlDataSource>
                               <ext:Store ID="deptStore" DataSourceID="SqlDataSource4" runat="server">
                                    <Reader>
                                        <ext:JsonReader ReaderID="DeptName">
                                            <Fields>
                                                <ext:RecordField Name="DeptName" />
                                            </Fields>
                                        </ext:JsonReader>
                                    </Reader>
                                </ext:Store>
    
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" 
        ConnectionString="<%$ ConnectionStrings:CXDB %>" 
        SelectCommand="SELECT [uID], [username] FROM [CX_UserBase] WHERE (([DEPID] = @DEPID) AND ([LevelID] = @LevelID))">
        <SelectParameters>
            <asp:Parameter DefaultValue="6" Name="DEPID" Type="Int32" />
            <asp:Parameter DefaultValue="1" Name="LevelID" Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
    <ext:Store ID="Store2" DataSourceID="SqlDataSource2" AutoLoad="true" runat="server">
        <Reader>
            <ext:JsonReader ReaderID="uID">
                <Fields>
                    <ext:RecordField Name="uID" Type="Int"></ext:RecordField>
                    <ext:RecordField Name="username" Type="String"></ext:RecordField>
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:ViewPort ID="ViewPort1" runat="server">
        <Body>
            <ext:ColumnLayout  ID="ColumnLayout1" runat="server" Split="true" FitHeight="true">
                <Columns>
                <ext:LayoutColumn ColumnWidth="0.3">
                    <ext:Panel ID="Panel4" runat="server" Width="400">
                        <Body>
                            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                                ConnectionString="<%$ ConnectionStrings:CXDB %>" 
                                SelectCommand="SELECT CX_UserBase.username, CX_SYS_Dept.DeptName, CX_UserBase.uID FROM CX_UserBase INNER JOIN CX_SYS_Dept ON CX_UserBase.DEPID = CX_SYS_Dept.ID"></asp:SqlDataSource>
                                <ext:Store ID="Store1" runat="server" DataSourceID="SqlDataSource1"  >
                                <Reader>
                                    <ext:JsonReader ReaderID="uID">
                                        <Fields>
                                            <ext:RecordField Name="uID" Type="Int" ></ext:RecordField>
                                            <ext:RecordField Name="username" Type="String"></ext:RecordField>
                                            <ext:RecordField Name="DeptName" Type="String"></ext:RecordField>
                                        </Fields>
                                    </ext:JsonReader>
                                </Reader>
                                    <AutoLoadParams>
                                         <ext:Parameter Name="start" Mode="Raw" Value="0" />
                                         <ext:Parameter Name="limit" Mode="raw" Value="10" />
                                     </AutoLoadParams> 
                                </ext:Store>
                                <ext:GridPanel AutoExpandColumn="username" ID="GridPanel1" runat="server" Height="400" StoreID="Store1" Title="员工列表" TrackMouseOver="true" Icon="UserHome">
                                    <ColumnModel ID="ColumnModel1" runat="server">
                                        <Columns>
                                            <ext:Column DataIndex="uID" ColumnID="Uid" Header="编号"></ext:Column>
                                            <ext:Column DataIndex="DeptName" ColumnID="DeptName" Header="所在部门"></ext:Column>
                                            <ext:Column DataIndex="username" ColumnID="username" Header="员工姓名"></ext:Column>
                                            <ext:Column Width="28" DataIndex="company" Sortable="false" MenuDisabled="true" Header="&nbsp;" Fixed="true">
                                            <Renderer Handler="return '';" />
                                        </ext:Column>
                                        </Columns>
                                    </ColumnModel>
                                    <SelectionModel>
                                        <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true">
                                            <AjaxEvents>
                                                <RowSelect OnEvent="RowSelect" Buffer="250">
                                                    <EventMask ShowMask="true" Target="CustomTarget" CustomTarget="#{ReportAdd}" />
                                                    <ExtraParams>
                                                        <%-- or can use params[2].id as value --%>
                                                        <ext:Parameter Name="uID" Value="this.getSelected().id" Mode="Raw" />
                                                    </ExtraParams>
                                                </RowSelect>
                                            </AjaxEvents>
                                        </ext:RowSelectionModel>
                                    </SelectionModel>
                                    <View>
                                        <ext:GridView runat="server">
                                            <HeaderRows>
                                                <ext:HeaderRow>
                                                    <Columns>
                                                        <ext:HeaderColumn>
                                                            <Component>
                                                                <ext:TextField ID="uidFilter" runat="server" EnableKeyEvents="true">
                                                                <Listeners>
                                                                    <KeyUp Handler="applyFilter();" Buffer="250" />                                                
                                                                </Listeners>
                                                            </ext:TextField>
                                                            </Component>
                                                        </ext:HeaderColumn>
                                                        <ext:HeaderColumn>
                                                            <Component>
                                                                <ext:ComboBox ID="deptFilter" runat="server" 
                                                                StoreID="deptStore"
                                                                TriggerAction="All"
                                                                Mode="Local"
                                                                DisplayField="DeptName"
                                                                ValueField="DeptName">    
                                                                <Listeners>
                                                                    <Select Handler="applyFilter();" />
                                                                </Listeners>     
                                                            </ext:ComboBox>
                                                            </Component>
                                                        </ext:HeaderColumn>
                                                        <ext:HeaderColumn>
                                                            <Component>
                                                                <ext:ComboBox ID="CompanyFilter" runat="server" 
                                                                StoreID="usernameStore"
                                                                TriggerAction="All"
                                                                Mode="Local"
                                                                DisplayField="username"
                                                                ValueField="username">    
                                                                <Listeners>
                                                                    <Select Handler="applyFilter();" />
                                                                </Listeners>     
                                                            </ext:ComboBox>
                                                            </Component>
                                                        </ext:HeaderColumn>
                                                        <ext:HeaderColumn>
                                                            <Component>
                                                                <ext:Button ID="ClearFilterButton" runat="server" Icon="Cancel">
                                                                <ToolTips>
                                                                    <ext:ToolTip ID="ToolTip1" runat="server" Html="清空选择" />
                                                                </ToolTips>
                                                                
                                                                <Listeners>
                                                                    <Click Handler="clearFilter();" />
                                                                </Listeners>                                            
                                                            </ext:Button>
                                                            </Component>
                                                        </ext:HeaderColumn>
                                                    </Columns>
                                                </ext:HeaderRow>
                                            </HeaderRows>
                                        </ext:GridView>
                                    </View>
                                    <BottomBar>
                                        <ext:PagingToolBar 
                                            ID="PagingToolBar1" 
                                            runat="server" 
                                            PageSize="10" 
                                            StoreID="Store1" 
                                            />
                                    </BottomBar>
                                    <LoadMask ShowMask="true" />
                                </ext:GridPanel>
                        </Body>
                    </ext:Panel>
                </ext:LayoutColumn>
                    
              <ext:LayoutColumn ColumnWidth="0.7">
   
                            <ext:FormPanel  ID="ReportAdd" AutoScroll="true" Title="员工诚信档案记录表"  runat="server" BodyStyle="padding:5px;" ButtonAlign="Right"
                                Frame="true" >
                                <Body>
                                    <ext:FormLayout ID="FormLayout1" runat="server">
                                        <ext:Anchor>
                                            <ext:Label ID="Tfusername" Disabled=true runat="server" FieldLabel="员工姓名"></ext:Label>
                                        </ext:Anchor>
                                        <ext:Anchor>
                                            <ext:Hidden ID="TfUserID" runat="server"></ext:Hidden>
                                        </ext:Anchor>
                                        <ext:Anchor>
                                            <ext:Label ID="TfDeptName" Disabled="true" runat="server" FieldLabel="所在部门">
                                            </ext:Label>
                                        </ext:Anchor>
                                        <ext:Anchor>
                                            <ext:Hidden ID="TfDeptID" runat="server" FieldLabel="部门ID"></ext:Hidden>
                                        </ext:Anchor>
                                        <ext:Anchor>
                                            <ext:DateField ID="TfAccident_time" EmptyText="请选择时间"    FieldLabel="安全生产中的事故时间" runat="server">
                                            </ext:DateField>
                                        </ext:Anchor>
                                        <ext:Anchor>
                                            <ext:ComboBox ID="TfAccident_duty" Editable="false" EmptyText="请选择" Width="120" FieldLabel="安全生产中的事故责任类型" runat="server">
                                            <Items>
                                                <ext:ListItem Text="主要责任" />
                                                <ext:ListItem Text="次要责任" />
                                                <ext:ListItem Text="管理责任" />
                                            </Items>
                                            </ext:ComboBox>
                                        </ext:Anchor>
                                        <ext:Anchor Horizontal="100%">
                                            <ext:TextArea  ID="TfAccident_reason" FieldLabel="安全生产中的事故原因" runat="server">
                                            </ext:TextArea>
                                        </ext:Anchor>
                                        
                                        <ext:Anchor>
                                             <ext:ComboBox 
                                                            FieldLabel="安监部领导" 
                                                            Width="150"
                                                            ID="TfSafty_MasterId" 
                                                            runat="server" 
                                                            StoreID="Store2" 
                                                            Editable="false"
                                                            DisplayField="username"
                                                            ValueField="uID"
                                                            TypeAhead="true" 
                                                            Mode="Local"
                                                            ForceSelection="true"
                                                            EmptyText="请选择..."
                                                            Resizable="true"
                                                            SelectOnFocus="true">
                                            </ext:ComboBox>   
                                        </ext:Anchor>
                                        <ext:Anchor>
                                            <ext:FileUploadField ID="tffileupload" FieldLabel ="附件" Width="200" runat="server"></ext:FileUploadField>
                                        </ext:Anchor>
                                        <ext:Anchor>
                                            <ext:Label ID="Label2" runat="server" FieldLabel="注意" Text="附件仅支持支持.zip和.rar文件格式，大小不能超过5M。否则不能上传成功，请提交请仔细检查，谢谢！"></ext:Label>
                                        </ext:Anchor>
                                    </ext:FormLayout>
                                </Body>
                                <Buttons>
                                    <ext:Button ID="Button1"   runat="server" Icon="Disk" Text="提交">
                                    <AjaxEvents>
                                        <Click OnEvent="SubReportAdd">
                                            <EventMask ShowMask="true" Msg="员工诚信档案记录表提交中..." MinDelay="1000" />
                                        </Click>
                                    </AjaxEvents>
                                    </ext:Button>
                                </Buttons>
                            </ext:FormPanel>
 
                </ext:LayoutColumn>
                </Columns>
            </ext:ColumnLayout>
        </Body>
    </ext:ViewPort>
    <ext:Window ID="Window1" runat="server" ShowOnLoad="false"  Collapsible="false" Icon="ErrorGo" Closable="false" Modal="true" Title="错误">
        <Body>
        <br />
        <ext:Label runat="server" ID="ErrLabel" Text="您无权进行此项操作！"></ext:Label>
        </Body>
    </ext:Window>
</asp:Content>

